home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 5 / BBS in a Box -Volume V (BBS in a Box) (April 1992).iso / Files / Prog / M / Mac gperf 1.9.cpt / Mac gperf 1.9 / src / boolarray.c next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  3.2 KB  |  105 lines  |  [TEXT/KAHL]

  1. /* Fast lookup table abstraction implemented as a Guilmette Array
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  4.  
  5. This file is part of GNU GPERF.
  6.  
  7. GNU GPERF is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU GPERF is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU GPERF; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25. #include "options.h"
  26. #include "xmalloc.h"
  27. #include "boolarray.h"
  28.  
  29.     /* Locally visible BOOL_ARRAY object. */
  30.  
  31. static BOOL_ARRAY    bool_array;
  32.  
  33.  
  34.     /***********************************************************************\
  35.     *                                                                        *
  36.     * name:        bool_array_destroy                                            *
  37.     *                                                                        *
  38.     * descr:    Print out debugging diagnostics.                            *
  39.     *                                                                        *
  40.     \***********************************************************************/
  41.  
  42. void bool_array_destroy()
  43. {
  44.     if ( OPTION_ENABLED( option, DEBUG ) )
  45.         fprintf( stderr, "\ndumping boolean array information\n"
  46.                          "size = %d\nend of array dump\n", bool_array.size );
  47.     free( bool_array.storage_array );
  48. }
  49.  
  50.  
  51.     /***********************************************************************\
  52.     *                                                                        *
  53.     * name:        bool_array_init                                                *
  54.     *                                                                        *
  55.     * descr:    Initialize bool array.                                        *
  56.     *                                                                        *
  57.     \***********************************************************************/
  58.  
  59. void bool_array_init( int size )
  60. {
  61.     bool_array.iteration_number    = 1;
  62.     bool_array.size                = size;
  63.     bool_array.storage_array    = (int *)xmalloc( size * sizeof(*bool_array.storage_array) );
  64.  
  65.     memset( bool_array.storage_array, 0, size * sizeof(*bool_array.storage_array) );
  66. }
  67.  
  68.     /***********************************************************************\
  69.     *                                                                        *
  70.     * name:        lookup                                                        *
  71.     *                                                                        *
  72.     * descr:    Look up index in bool array.                                *
  73.     *                                                                        *
  74.     \***********************************************************************/
  75.  
  76. bool lookup( int index )
  77. {
  78.     if ( bool_array.storage_array[index] == bool_array.iteration_number  )
  79.         return 1;
  80.     else
  81.     {
  82.         bool_array.storage_array[index] = bool_array.iteration_number;
  83.         return 0;
  84.     }
  85. }
  86.  
  87.     /***********************************************************************\
  88.     *                                                                        *
  89.     * name:        bool_array_reset                                            *
  90.     *                                                                        *
  91.     * descr:    Reset boolarray.                                            *
  92.     *                                                                        *
  93.     \***********************************************************************/
  94.  
  95.  
  96. void bool_array_reset()  
  97. {
  98.     /*    If we wrap around it's time to zero things out again!
  99.         However, this only occurs once about every 2^31 iterations,
  100.         so it should probably never happen! */
  101.             
  102.     if ( bool_array.iteration_number++ == 0 )
  103.         memset( bool_array.storage_array, 0, bool_array.size * sizeof(*bool_array.storage_array) );
  104. }
  105.